package org.example.ims.Repository.Base;

import org.example.ims.Entity.Base.Supplier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SupplierRepository extends JpaRepository<Supplier, Integer> {
    Supplier findBySupplierName(String name);

    @Query("SELECT s FROM Supplier s " +
            "WHERE (:name IS NULL OR s.supplierName = :name) " +
            "AND (:contact IS NULL OR s.contactPerson = :contact )" +
            "AND (:phone IS NULL OR s.contactPhone = :phone)")
    Page<Supplier> searchSuppliers(@Param("name") String name,
                                   @Param("contact") String contact,
                                   @Param("phone") String phone,
                                   Pageable pageable);
}
